﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Globalization;
using System.Web.Mvc;
using InfoTech.Core.Service;
using InfoTech.LanTranh.MucVu.Bussiness;
using System.Linq;

namespace InfoTech.LanTranh.MucVu.Service
{
    public class GIAODANService : BaseService
    {
        public static IEnumerable<SelectListItem> Get_List_Days()
        {
            int min = 1;
            int max = 31;
            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem() { Text = "--- {Chọn Ngày} ---", Value = "" });
            for (int i = min; i <= max; i++)
            {
                list.Add(new SelectListItem()
                {
                    Text = i + "",
                    Value = i + ""
                });
            }
            return list;
        }

        public static IEnumerable<SelectListItem> Get_List_Months()
        {
            int min = 1;
            int max = 12;
            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem() { Text = "--- {Chọn Tháng} ---", Value = "" });
            for (int i = min; i <= max; i++)
            {
                list.Add(new SelectListItem()
                {
                    Text = i + "",
                    Value = i + ""
                });
            }
            return list;
        }

        public static IEnumerable<SelectListItem> Get_List_Years()
        {
            int min = 1900;
            int max = DateTime.Now.Year;
            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem() { Text = "--- {Chọn Năm} ---", Value = "" });
            for (int i = max; i >= min; i--)
            {
                list.Add(new SelectListItem()
                {
                    Text = i + "",
                    Value = i + ""
                });
            }
            return list;
        }

        public static bool CheckBirthday(int? day, int? month, int? year)
        {
            bool result = true;
            //if (!string.IsNullOrEmpty(day) && !string.IsNullOrEmpty(month) && !string.IsNullOrEmpty(year))
            //{
            //    DateTime dateTime;
            //    if (!DateTime.TryParseExact(string.Format("{0}/{1}/{2}", day, month, year), "dd/MM/yyyy", new DateTimeFormatInfo(), DateTimeStyles.AllowTrailingWhite, out dateTime))
            //    {
            //        result = false;
            //    }
            //}
            return result;
        }

        public static bool Check_Insert_GIAODAN(GIAODAN giaodan)
        {
            return true;
        }

        public static bool Check_Update_GIAODAN(GIAODAN giaodan)
        {
            return true;
        }

        public static bool Check_Delete_GIAODAN(string[] strings)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &= dataContext.GetTable<GIAODAN>().FirstOrDefault(c => strings.Contains(c.PARENTID + "")) == null;
            result &= dataContext.GetTable<GIAODAN>().FirstOrDefault(c => strings.Contains(c.MOTHERID + "")) == null;
            result &= dataContext.GetTable<HOGIADINH>().FirstOrDefault(c => strings.Contains(c.MACHUHO + "")) == null;
            return result;
        }

        public static void Delete(GIAODAN giaodan)
        {
            HOGIADINH_GIAODANService.Delete(giaodan);
            SOBITICHService.Delete(giaodan);
            GIAODAN_DIACHIService.Delete(giaodan);
            SOHONNHANService.Delete(giaodan);
            SOTANHIENService.Delete(giaodan);
            SOXUCDAUService.Delete(giaodan);

        }

    }
}
